package com.buba.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.buba.service.DepartmentManagementService;
import common.R;
import entity.system.DepartmentManagement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.buba.service.DepartmentManagementService;
import common.R;
import entity.device.DeviceType;
import entity.system.DepartmentManagement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 部门管理 前端控制器
 * </p>
 *
 * @author beisheng
 * @since 2023-05-18
 */
@RestController
@RequestMapping("/department-management")
public class DepartmentManagementController {
    @Autowired
    private DepartmentManagementService departmentManagementService;

    /**
     * @return common.R
     * @Author atlong
     * @Description 树形查询部门信息
     * @Date 2023/6/5 8:41
     * @Param []
     **/
    @GetMapping("selAllDepartments")
    public R selAllDepartments() {
        List<DepartmentManagement> list = departmentManagementService.selAllDepartments();
        return R.success(list);
    }

    @GetMapping("selUserDepartment")
    public R selUserDepartment() {
        List<DepartmentManagement> list = departmentManagementService.selUserDepartment();
        return R.success(list);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 查询全部部门
     * @Date: 2023/6/5 15:37
     * @Return: common.R
     * @Param: []
     */

    @GetMapping("/selAllDepartment")
    public R selAllDepartment(){
        return R.success(departmentManagementService.list(new QueryWrapper<DepartmentManagement>().eq("delete_flag",0)));
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 根据ID查询部门信息
     * @Date: 2023/6/6 9:58
     * @Return: entity.system.DepartmentManagement
     * @Param: [id]
     */

    @PostMapping("/selOneDepartment")
    public DepartmentManagement selOneDepartment(@RequestBody Integer id){
        DepartmentManagement byId = departmentManagementService.getById(id);
        return byId;
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 根据ID查询部门信息
     * @Date: 2023/6/6 9:58
     * @Return: entity.system.DepartmentManagement
     * @Param: [id]
     */

    @PostMapping("/selOneDepartments/{id}")
    public R selOneDepartments(@PathVariable("id") Integer id){
        DepartmentManagement byId = departmentManagementService.getById(id);
        return R.success(byId);
    }
}

